package com.alipay.model.dto;

import com.alipay.model.enums.ResponseCodeEnum;
import lombok.Data;

import java.io.Serializable;

/**
 * @author Jun
 */
@Data
public class Response implements Serializable {
    /**
     * 本次请求唯一id
     */
    private String requestId;

    /**
     * 响应的状态码
     */
    private Integer code;

    /**
     * 响应的信息
     */
    private String msg;


    /**
     * 响应的数据
     */
    private Object data;


    public Response(String requestId, ResponseCodeEnum codeEnum, Object data) {
        this.requestId = requestId;
        this.code = codeEnum.getCode();
        this.msg = codeEnum.getMsg();
        this.data = data;
    }


    public static Response newResponse(String requestId, ResponseCodeEnum codeEnum, Object data) {
        return new Response(requestId, codeEnum, data);
    }


    public static Response newFailure(String requestId, ResponseCodeEnum codeEnum) {
        return newResponse(requestId, codeEnum, null);
    }


    public static Response newSuccess(String requestId, Object data) {
        return newResponse(requestId, ResponseCodeEnum.SUCCESS, data);
    }
}
